#ifndef _BUOLA_MEDIA_SUPPORT_PULSE_CPULSESTREAM_H_
#define _BUOLA_MEDIA_SUPPORT_PULSE_CPULSESTREAM_H_

#include <blackbox/blackbox.h>
#include <buola/container/cbuffer.h>

#include <pulse/context.h>
#include <pulse/stream.h>

namespace buola { namespace media { namespace pulse {

class CPulseContext;

class CPulseStream
{
public:
    CPulseStream(CPulseContext &pCtx,const std::string &pName,int pRate=44100,int pChannels=1,
                                                 pa_sample_format_t pFormat=PA_SAMPLE_S16LE);
    ~CPulseStream();

    void ConnectPlayback();

    void Write(const void *pData,std::size_t pSize);

    template<typename tType>
    void Write(const CBuffer<tType> &pBuffer)
    {
        Write(pBuffer.Data(),pBuffer.Size()*sizeof(tType));
    }

    CPulseContext &GetContext() {   return mCtx;    }

    bool WaitForConnection();

private:
    pa_stream *mStream;

    CPulseContext &mCtx;
};

/*namespace pulse*/ } /*namespace media*/ } /*namespace buola*/ }

#endif

